package co.inventario.modelo.fachada;


import java.sql.SQLException;
import java.util.ArrayList;

import co.inventario.entidad.ConceptoKardexDTO;
import co.inventario.modelo.negocio.ConceptoKardexNegocio;
import co.inventario.transversal.DAOFactorySQLServer;

public class ConceptoKardexFachada {

	public void crear(ConceptoKardexDTO conceptoKardexDTO) throws Exception, SQLException {
		DAOFactorySQLServer daoFactorySQLServer = new DAOFactorySQLServer();
		ConceptoKardexNegocio conceptoKardexNegocio = new ConceptoKardexNegocio();
		try {
			conceptoKardexNegocio.crear(conceptoKardexDTO, daoFactorySQLServer.obtenerConexion());
			daoFactorySQLServer.confirmarTransaccion();
		} catch (SQLException exception) {
			daoFactorySQLServer.cancelarTransaccion();
			throw new Exception("Se ha presentado un problema intentando crear el Concepto kardex.");
		} catch (Exception exception) {
			daoFactorySQLServer.cancelarTransaccion();
			throw exception;
		} finally {
			daoFactorySQLServer.cerrarConexion();
		}
	}

	public void actualizar(ConceptoKardexDTO conceptoKardexDTO) throws Exception, SQLException {
		DAOFactorySQLServer daoFactorySQLServer = new DAOFactorySQLServer();
		ConceptoKardexNegocio conceptoKardexNegocio = new ConceptoKardexNegocio();
		try {
			conceptoKardexNegocio.actualizar(conceptoKardexDTO, daoFactorySQLServer.obtenerConexion());
			daoFactorySQLServer.confirmarTransaccion();
		} catch (SQLException exception) {
			daoFactorySQLServer.cancelarTransaccion();
			throw new Exception("Se ha presentado intentando actualizar el Concepto kardex.");
		} catch (Exception exception) {
			throw exception;
		} finally {
			daoFactorySQLServer.cerrarConexion();
		}
	}

	public ArrayList<ConceptoKardexDTO> consultarTodo() throws Exception, SQLException {
		DAOFactorySQLServer daoFactorySQLServer = new DAOFactorySQLServer();
		ConceptoKardexNegocio conceptoKardexNegocio = new ConceptoKardexNegocio();
		ArrayList<ConceptoKardexDTO> conceptoKardexDTOLista = null;
		try {
			conceptoKardexDTOLista = conceptoKardexNegocio.consultarTodo(daoFactorySQLServer.obtenerConexion());
		} catch (SQLException exception) {
			daoFactorySQLServer.cancelarTransaccion();
			throw new Exception("Se ha presentado intentando consultar los Conceptos kardex.");
		} catch (Exception exception) {
			throw exception;
		} finally {
			daoFactorySQLServer.cerrarConexion();
		}
		return conceptoKardexDTOLista;
	}
}
